package com.ctg.itrdc.imageconsole.servcie.user;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerMicroUserDao;
import com.ctg.itrdc.imageconsole.data.dto.user.UserDTO;
import com.ctg.itrdc.imageconsole.data.entity.user.DockerMicroUser;
import com.ctg.itrdc.paspsdk.data.dao.IBaseDao;

@Component("userServiceAux")
public class UserServiceAux {

	@Resource 
	IBaseDao baseDao;
	
	@Resource
	IDockerMicroUserDao microUserDao;
	
	public Object selectUsers(String userCode, Integer pageNum, Integer pageSize) {
		String sql = "select id as userId, sys_user_id as sysUserId, code as userCode, name as userName, password as password" +
				" from docker_micro_user where available = ?";
		List<Object> params = new ArrayList<Object>();
		params.add("1");
		if(null != userCode) {
			sql = sql + " and code like ?";			
			params.add(userCode);		
		}		
		return baseDao.jdbcFindPageInfo(sql, UserDTO.class, params, pageNum, pageSize);
	}
	
	public UserDTO selectUser(Long userId) {
		DockerMicroUser microUser = microUserDao.selectById(userId);
		if(null == microUser)
			return null;
		UserDTO userDTO = new UserDTO();
		userDTO.setUserId(userId);
		userDTO.setUserCode(microUser.getCode());
		userDTO.setPassword(microUser.getPassword());
		userDTO.setUserName(microUser.getName());
		return userDTO;
	}
	
}
